/*
 * This file is part of Catfish.
 * Copyright (C) 2010 Namazu Studios LLC
 * 
 * Catfish is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as 
 * published by the Free Software Foundation, either version 3 of 
 * the License, or (at your option) any later version.
 * 
 * Catfish is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with Catfish.  If not, please visit:
 *  
 * http://www.gnu.org/licenses/
 *  
 */
package com.namazustudios.catfish.converter;

import java.lang.reflect.Type;

/**
 * Converts objects to and from a suitable type for the datastore.
 * 
 * @author patrick
 * 
 * @param <T>
 *            a type compatible with the datastore
 * @param <U>
 *            any other user-defined type
 * 
 */
public interface Converter<T, U> {

    /**
     * Converts the given objects from the Datastore to the user defined type.
     * 
     * @param cls
     *            the type of the field or generic type.
     * @param existing
     *            the existing value of the object in the field. For Collection
     *            types this will always be null
     * @param obj
     *            the value in the datastore
     * 
     * @return the converted object
     */
    public U load(Type cls, U existing, T obj);

    /**
     * Converts the object to a type suitable for the Datastore.
     * 
     * @param the
     *            object to convert from
     * 
     * @return the converted object
     */
    public T store(U obj);

}
